using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Protocol;
using System;
namespace MicroMsg.Scene
{
	public class NetSceneBindOpMobileForReg : NetSceneBaseEx<BindOpMobileRequest, BindOpMobileResponse, BindOpMobileRequest.Builder>
	{
		private const string TAG = "NetSceneBindOpMobileForReg";
		public const int OPCODE_BINDMOBILE_REG_READY = 5;
		public const int OPCODE_BINDMOBILE_REG_CHECK = 6;
		public const int OPCODE_BINDMOBILE_REG_CHECKED = 7;
		public static int DIALFLAG_NO = 0;
		public static int DIALFLAG_YES = 1;
		public static string mMobileNumber;
		public static string mTicket;
		public void doScene(string mobile)
		{
			Log.smethod_4("NetSceneBindOpMobileForReg", "mobile register (1/3), set mobile =" + mobile);
			NetSceneBindOpMobileForReg.mMobileNumber = mobile;
			this.doSceneEx(mobile, "", 5, NetSceneBindOpMobileForReg.DIALFLAG_NO, "");
		}
		public void doSceneVerify(string verifyCode)
		{
			Log.smethod_4("NetSceneBindOpMobileForReg", "mobile register (2/3) , set verify =" + verifyCode);
			this.doSceneEx(NetSceneBindOpMobileForReg.mMobileNumber, verifyCode, 6, NetSceneBindOpMobileForReg.DIALFLAG_NO, "");
		}
		public void doSceneDialForVerifyCode(string lang)
		{
			Log.smethod_4("NetSceneBindOpMobileForReg", "mobile register (2/3) ,dial for verify code, lang =" + lang);
			this.doSceneEx(NetSceneBindOpMobileForReg.mMobileNumber, "", 5, NetSceneBindOpMobileForReg.DIALFLAG_YES, lang);
		}
		private void doSceneEx(string mobile, string verifyCode, int opCode, int dialFlag, string dialLang)
		{
			base.beginBuilder();
			this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(0);
			this.mBuilder.UserName = "";
			this.mBuilder.Mobile = mobile;
			this.mBuilder.Opcode = opCode;
			this.mBuilder.Verifycode = verifyCode;
			this.mBuilder.DialFlag = dialFlag;
			this.mBuilder.DialLang = dialLang;
			this.mSessionPack.mConnectMode = 2;
			this.mSessionPack.mCmdUri = "/cgi-bin/micromsg-bin/bindopmobileforreg";
			base.endBuilder();
		}
		protected override void onSuccess(BindOpMobileRequest request, BindOpMobileResponse response)
		{
			int opcode = request.Opcode;
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			if (ret != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneBindOpMobileForReg", string.Concat(new object[]
				{
					"error in opCode =",
					opcode,
					"  ret = ",
					ret
				}));
				this.postFailedEvent(request, opcode, (int)ret);
				return;
			}
			NetSceneBindOpMobileForReg.mTicket = response.Ticket;
			Log.smethod_4("NetSceneBindOpMobileForReg", string.Concat(new object[]
			{
				"success. opCode =",
				opcode,
				"  ticket = ",
				NetSceneBindOpMobileForReg.mTicket
			}));
			if (opcode != 5)
			{
				if (opcode == 6)
				{
					Log.smethod_4("NetSceneBindOpMobileForReg", NetSceneBindOpMobileForReg.mMobileNumber + "verify success");
					EventCenter.postEvent(EventConst.ON_NETSCENE_MOBILEREG_VERIFY_SUCCESS, null, null);
				}
				return;
			}
			if (request.DialFlag == NetSceneBindOpMobileForReg.DIALFLAG_YES)
			{
				Log.smethod_4("NetSceneBindOpMobileForReg", "get voice verify code success,phone =" + NetSceneBindOpMobileForReg.mMobileNumber);
				EventCenter.postEvent(EventConst.ON_NETSCENE_MOBILE_VOICEDIAL_SUCCESS, null, null);
				return;
			}
			Log.smethod_4("NetSceneBindOpMobileForReg", "set phone success,phone =" + NetSceneBindOpMobileForReg.mMobileNumber);
			EventCenter.postEvent(EventConst.ON_NETSCENE_MOBILEREG_SETPHONE_SUCCESS, null, null);
		}
		protected override void onFailed(BindOpMobileRequest request, BindOpMobileResponse response)
		{
			int opcode = request.Opcode;
			this.postFailedEvent(request, opcode, -800000);
		}
		private void postFailedEvent(BindOpMobileRequest request, int opCode, int int_0)
		{
			if (opCode != 5)
			{
				if (opCode == 6)
				{
					EventCenter.postEvent(EventConst.ON_NETSCENE_MOBILEREG_VERIFY_ERR, int_0, null);
				}
				return;
			}
			if (request != null && request.DialFlag == NetSceneBindOpMobileForReg.DIALFLAG_YES)
			{
				Log.smethod_4("NetSceneBindOpMobileForReg", "get voice verify code failed,phone =" + NetSceneBindOpMobileForReg.mMobileNumber);
				EventCenter.postEvent(EventConst.ON_NETSCENE_MOBILE_VOICEDIAL_ERR, int_0, null);
				return;
			}
			EventCenter.postEvent(EventConst.ON_NETSCENE_MOBILEREG_SETPHONE_ERR, int_0, null);
		}
	}
}
